<template>
  <div>
    <van-sticky>
      <van-search
        v-model="value"
        placeholder="请输入搜索关键词"
        input-align="center"
        disabled
        @click="goto('/search')"
      />
    </van-sticky>

    <div class="contents">
      <van-sidebar v-model="activeKey">
        <van-sidebar-item
          v-for="item in goodscategory"
          :key="item.cat_one_id"
          :title="item.cat_one_id"
          @click="goodlist(item.cat_one_id)"
        />
      </van-sidebar>
      <div class="article">
        <div class="outside">
          <div class="clists" v-for="item in goodlists" :key="item.goods_id">
            <van-image
              round
              width="80px"
              height="80px"
              :src="item.goods_small_logo"
              @click="gotodetails(item.goods_id)"
            />
            <p>{{ item.cat_id }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "Discover",
  data() {
    return {
      value: "",
      activeKey: 0,
      goodscategory: [],
      goodlists: [],
    };
  },
  async created() {
    const {
      data: { data },
    } = await this.$request.get("/api/goods/category");
    this.goodscategory = data.list;
    // 进去显示第一条数据
    this.goodlist(this.goodscategory[0].cat_one_id);
  },
  methods: {
    goto(url) {
      this.$router.push(url);
    },
    async goodlist(category) {
      const { data } = await this.$request.get("/api/goods", {
        params: {
          cat_one_id: category,
          pagesize: 200,
        },
      });
      this.goodlists = data.data.list;
    },
    gotodetails(id) {
      this.$router.push("/goods/" + id);
    },
  },
  computed: {},
};
</script>
<style lang="scss" scoped>
.van-search {
  border-bottom: 1px solid #d9d9d9;
}
.contents {
  .van-sidebar {
    border-right: 1px solid #d9d9d9;
    position: fixed;
  }
  .article {
    float: right;
    padding-bottom: 20px;
    // height: 500px;
    width: calc(100% - 81px);
    .outside {
      background-color: #eee;
      display: flex;
      justify-content: space-evenly;
      flex-wrap: wrap;
      padding: 10px;
      box-sizing: border-box;
      .clists {
        margin-bottom: 20px;
        width: 100px;
        height: 130px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-direction: column;
      }
    }
  }
}
</style>
